package com.jinyi.wwdeng.ui.launch.impl

import com.jinyi.base.mvp.BaseModel
import com.jinyi.base.network.IRequestCallback
import com.jinyi.base.network.NetworkUtils
import com.jinyi.wwdeng.network.ApiService
import com.jinyi.wwdeng.ui.launch.contract.LaunchContract
import org.json.JSONObject

/**
 * JinYiTest
 *
 * @Author：wwdeng
 * @CreateTime：2024/4/14 18:42
 * <pre>
 * Model层  接口实现类
</pre> *
 */
class LaunchModelImpl(iCallBack: LaunchContract.Presenter) : BaseModel<LaunchContract.Presenter>(iCallBack), LaunchContract.Model {

    /**
     * 获取地区转发
     */
    override fun loadTimezoneRequest(params: JSONObject) {
        val httpUrl = ApiService.BASE_URL + ApiService.API_URL.API_TIMEZONE_URL
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onTimeZoneSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onFailure(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
            }
        })
    }

    /**
     * APP 配置请求
     */
    override fun loadAppInfoRequest(params: JSONObject) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onAppInfoSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onFailure(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
            }
        })
    }

    override fun destory() {
        super.destory()
//        NetworkUtils.onCancelRequest()
    }
}
